{{define "infoCollection/livingStatus.html"}}
<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">生活方式</h3>
    </div>
    <!-- /.box-header -->
    <!-- form start -->
    <form class="form-horizontal" id="livingStatusForm">
        <div class="box-body">
            <div class="form-group">
                <label class="control-label col-sm-2">
                    吸烟:
                </label>
                <div class="radio col-sm-4">
                    <input type="radio" name="isSmoking" value="否" class="minimal" checked>
                    否&nbsp;&nbsp;
                    <input type="radio" name="isSmoking" value="是" class="minimal">
                    是
                </div>
            </div>
            <div class="form-group" id="smokingStatus" style="display: none;">
                <label class="control-label col-sm-2">吸烟情况:
                </label>
                <div class="radio col-sm-4">
                    <input type="radio" name="smokingStatus" value="正在吸" class="minimal">
                    正在吸
                    <input type="radio" name="smokingStatus" value="已戒烟" class="minimal">
                    已戒烟
                </div>
            </div>

            <div class="form-group" id="zhengzaixi" style="display: none;">
                <div class="col-sm-offset-2 col-sm-3">
                    <span style="font-weight: bold;color: red;">吸烟年限:</span>
                    <input type="text" class="form-control" name="smokingYearsForNow" id="smokingYearsForNow">
                    <span style="font-weight: bold;color: red;">每天几只:</span>
                    <input type="text" class="form-control" name="smokingAmountForNow" id="smokingAmountForNow">
                </div>
            </div>
            <div class="form-group" id="yijieyan" style="display: none;">
                <div class="col-sm-offset-2 col-sm-3">
                    <span style="font-weight: bold;color: red;">戒烟年限:</span>
                    <input type="text" class="form-control" name="smokingYearsForGiveUp" id="smokingYearsForGiveUp">
                    <span style="font-weight: bold;color: red;">曾经吸烟年限:</span>
                    <input type="text" class="form-control" name="smokingYearsForHistory" id="smokingYearsForHistory">
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-2">
                    饮酒:
                </label>
                <div class="radio col-sm-10">
                    <input type="radio" name="drinking" value="不饮酒" class="minimal" checked>
                    不饮酒&nbsp;&nbsp;
                    <input type="radio" name="drinking" value="少量饮酒" class="minimal">
                    少量饮酒&nbsp;&nbsp;
                    <input type="radio" name="drinking" value="大量饮酒" class="minimal">
                    大量饮酒&nbsp;&nbsp;(白酒>=3次/周,每次>=2两)
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-sm-2">
                    运动习惯:
                </label>
                <div class="radio col-sm-4">
                    <input type="radio" name="sportStatus" value="经常运动" class="minimal" checked>
                    经常运动&nbsp;&nbsp;
                    <input type="radio" name="sportStatus" value="缺乏运动" class="minimal">
                    缺乏运动&nbsp;
                </div>
                <div class="col-sm-6" style="padding-top: 7px;">
                    <span style="font-weight: bold;color: red;">经常运动标准&nbsp;</span>:相当于快步周的中等强度运动,且每周>=3次,每次>=30分钟,包含中度、重度体力劳动者
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-sm-2">
                    膳食习惯:
                </label>
                <div class="radio col-sm-10">
                    口味:&nbsp;
                    <input type="radio" name="flavor" value="偏淡" class="minimal" checked>&nbsp;&nbsp;偏淡
                    <input type="radio" name="flavor" value="偏咸" class="minimal">&nbsp;&nbsp;偏咸
                    <input type="radio" name="flavor" value="适中" class="minimal">&nbsp;&nbsp;适中
                    <br><br>
                    荤素:&nbsp;
                    <input type="radio" name="meatAndVeg" value="偏荤" class="minimal" checked>&nbsp;&nbsp;偏荤
                    <input type="radio" name="meatAndVeg" value="偏素" class="minimal">&nbsp;&nbsp;偏素
                    <input type="radio" name="meatAndVeg" value="均衡" class="minimal">&nbsp;&nbsp;均衡
                    <br><br>
                    吃蔬菜(每日食用6两蔬菜):&nbsp;
                    <input type="radio" name="vegetables" value="0" class="minimal" checked>&nbsp;&nbsp;>=5天/周
                    <input type="radio" name="vegetables" value="1" class="minimal">&nbsp;&nbsp;3-4天/周
                    <input type="radio" name="vegetables" value="2" class="minimal">&nbsp;&nbsp;<=2天/周
                    <br><br>
                    吃水果(每日食用4两水果):&nbsp;
                    <input type="radio" name="fruit" value="0" class="minimal" checked>&nbsp;&nbsp;>=5天/周
                    <input type="radio" name="fruit" value="1" class="minimal">&nbsp;&nbsp;3-4天/周
                    <input type="radio" name="fruit" value="2" class="minimal">&nbsp;&nbsp;<=2天/周
                </div>
            </div>

        </div>
        <!-- /.box-body -->
        <div class="box-footer">
        {{/*<button type="submit" class="btn btn-default">Cancel</button>*/}}
            <button type="button" class="btn btn-info btn-lg middleBtn" id="livingStatusSignIn" onclick="saveLivingStatus()">保存</button>
        </div>
        <!-- /.box-footer -->
    </form>
</div>
<script>
    $(function () {
        if (canUpdate != null && canUpdate != undefined && !canUpdate) {
            $("#livingStatusSignIn").hide();
        }

        $("input:radio[name='isSmoking']").on('ifChanged', function (event) {
            if ($(this).is(':checked')) {
                if ($(this).val() == "是") {
                    $("#smokingStatus").show();
                } else {
                    $("#smokingStatus").hide();
                    $("#zhengzaixi").hide();
                    $("#yijieyan").hide();
                }
                $("input:radio[name='smokingStatus']").iCheck("uncheck");
                clearSmokingStatus();
            }
        });

        $("input:radio[name='smokingStatus']").on('ifChanged', function (event) {
            //alert(event.type + ' callback');
            if ($(this).is(':checked')) {
                if ($(this).val() == "正在吸") {
                    $("#zhengzaixi").show();
                    $("#yijieyan").hide();
                    $("#smokingYearsForGiveUp").val("");
                    $("#smokingYearsForHistory").val("");
                } else if ($(this).val() == "已戒烟") {
                    $("#zhengzaixi").hide();
                    $("#yijieyan").show();
                    $("#smokingYearsForNow").val("");
                    $("#smokingAmountForNow").val("");
                }
            }
        });
    });

    function clearSmokingStatus() {
        $("#smokingYearsForNow").val("");
        $("#smokingAmountForNow").val("");
        $("#smokingYearsForGiveUp").val("");
        $("#smokingYearsForHistory").val("");
    }

    function saveLivingStatus() {
        let d = {};
        let t = $('#livingStatusForm').serializeArray();
        $.each(t, function () {
            if (this.value != "") {
                d[this.name] = this.value;
            }
        });
        let data = JSON.stringify(d);
        console.log("livingStatusData:", data);
        ajaxLoading("正在保存数据......");
        $.post("/infoCollection/save", {type: "livingStatus", id: $("#screenId").val(), data: data}, function (resp) {
            //console.log(resp);
            ajaxLoadEnd();
            if (resp.code == 0) {
                toastr.success(resp.msg,'',{"positionClass": "toast-top-center"});
                window.localStorage.setItem("currentTab","livingStatus");
                setTimeout(function () {
                    window.location.reload();
                }, 500);
            }else{
                toastr.warning(resp.msg, '提示', {
                    "progressBar": true,
                    "positionClass": "toast-top-center",
                    "timeOut": "5000",
                    "closeButton":true
                });
            }
        });
    }

    let isSmoking, smokingStatus, smokingYearsForNow, smokingAmountForNow, smokingYearsForGiveUp,
            smokingYearsForHistory;

    function livingStatusInit(livingStatusData) {
        $("#livingStatusForm").initForm({jsonValue: livingStatusData, isDebug: false});
        /*smokingStatus = livingStatusData.smokingStatus;
        smokingYearsForNow = livingStatusData.smokingYearsForNow;
        smokingAmountForNow = livingStatusData.smokingAmountForNow;
        smokingYearsForGiveUp = livingStatusData.smokingYearsForGiveUp;
        smokingYearsForHistory = livingStatusData.smokingYearsForHistory;*/
    }
</script>
{{end}}